package cn.imvc.core;

import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class HttpContext {

	public static ServletContext getContext() {
		return getSession().getServletContext();
	}

	public static HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder
				.currentRequestAttributes()).getRequest();
	}

	public static HttpSession getSession() {
		return getRequest().getSession();
	}

	public static Cookie[] getCookie() {
		return getRequest().getCookies();
	}

	public static HttpServletResponse getResponse() {
		return (HttpServletResponse) getRequest().getAttribute(
				"_ServletResponse_");
	}
	public static String getRootUrl() {
		return getContext().getAttribute("rootUrl").toString();
	}
	
	public static String getRootPath() {
		return getContext().getAttribute("rootPath").toString();
	}
	public static boolean isPost() {
		return getRequest().getMethod().equalsIgnoreCase("POST");
	}

	public static boolean isGet() {
		return getRequest().getMethod().equalsIgnoreCase("GET");
	}

}
